﻿using System;
using System.Data;
using System.Linq;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL;
using System.Collections;
using ASPNETVN.PORTAL.Components.Configuration;

namespace CDTM.Modules.HOME.Controls
{
    public partial class Style1 : ModulePage
    {
        protected string GetUrl(int itemID, string moduleIdType)
        {
            PortalDataSet ds = PortalConfiguration.GetPortalDataSet();
            foreach (PortalDataSet.TabRow tab in ds.Tab.Rows)
            {
                foreach (PortalDataSet.ModuleRow module in tab.GetModuleRows())
                {
                    if (module.ID == new Guid(this.Settings["CMS.ModuleID"].ToString()))
                    {
                        return string.Format("~/Default.aspx?tabid={0}&mid={1}&itemid={2}&page=detail", tab.ID, module.ID, itemID);
                    }
                }
            }
            return string.Format("~/Default.aspx");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack == false)
            {
                const int Level1 = 1;
                const int Level2 = 3;

                Hashtable settings = this.Settings;
                Guid moduleId = new Guid(settings["CMS.ModuleID"].ToString());
                
                // CMS: Đào tạo 1.
                DataTable dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.DaoTao.1").Tables[0];
                var query = (from r in dt.AsEnumerable()
                             select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(Level1);
                rptA1.DataSource = query;
                rptA1.DataBind();
                
                // CMS: Đào tạo 2.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.DaoTao.2").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(Level2);
                rptA2.DataSource = query;
                rptA2.DataBind();

                // CMS: Nghiên cứu 1.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.NghienCuu.1").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(Level2);
                rptB1.DataSource = query;
                rptB1.DataBind();

                // CMS: Nghiên cứu 2.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.NghienCuu.2").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(Level2);
                rptB2.DataSource = query;
                rptB2.DataBind();

                // CMS: Tuyển sinh 1.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.TuyenSinh.1").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(Level2);
                rptC1.DataSource = query;
                rptC1.DataBind();

                // CMS: Tuyển sinh 2.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.TuyenSinh.2").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(Level2);
                rptC2.DataSource = query;
                rptC2.DataBind();


                // CMS: Hoạt động nghiên cứu.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.HoatDongNghienCuu").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(10);
                rptD.DataSource = query;
                rptD.DataBind();

                // CMS: Nghiên cứu khoa học.
                dt = ASPNETVN.PORTAL.Modules.CMS.Components.Item.GetItemsByDisplayType(moduleId, "CDTM.TrangChu.NghienCuuKhoaHoc").Tables[0];
                query = (from r in dt.AsEnumerable()
                         select new { ID = r.Field<int>("ID"), Title = r.Field<string>("Title"), SubTitle = r.Field<string>("SubTitle"), PublishedDate = r.Field<DateTime>("PublishedDate"), ImagePath = r.Field<string>("ImagePath") }).OrderByDescending(x => x.PublishedDate).Take(10);
                rptE.DataSource = query;
                rptE.DataBind();
            }
        }
    }
}